// pages/index/index.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
  backgroundImage:[],
    userInfo:{
      nickName:"未登录"
    },
    hasUserInfo:false,
    canIUseGetUSerProfile: false,

    imgurl: [], // 设置为空数组
    indicatorDots: true,
    autoplay:true,
    interval:4000,
    duration:200,
  },

  /**
   * 组件的方法列表
   */
  methods: {
    jumptohair:function(){
      wx.switchTab({
        url: '/pages/hair/hair',
      })
    },
    jumptod:function(){
      wx.switchTab({
        url: '/pages/drink/drink',
      })
    },
    jumptologin:function(){
      wx.switchTab({
        url: '/pages/me/me',
      })
    },

   
    onLoad: function(options) {
    
      this.fetchimg();
      this.bi();
      const userInfo = wx.getStorageSync('userInfo');
      this.setData({
        userInfo: userInfo,
       
      });
      console.log(userInfo);
      // 在这里可以使用 userInfo 数据
      
 
    },
    fetchimg: function () {
     // 调用后端接口获取图片数据
  wx.request({
    url: 'http://localhost:8080/getbi1?param1=classpath:static/swiper/&param2=http://localhost:8080/swiper/', // 修改为你的后端接口地址
    success: (res) => {
      this.setData({
        imgurl: res.data // 将后端返回的图片数据存储到 data 的 imgurl 数组中
      })
    },
    fail: (error) => {
      console.log(error)
    }
  })
    },
    bi:function(){
      wx.request({
        url: 'http://localhost:8080/getbi1?param1=classpath:static/index-background/&param2=http://localhost:8080/index-background/',
        method: 'GET',
        success: (res) => {
          console.log(res)
          console.log(res.data)
          const imageURL = res.data;
          
          this.setData({
            backgroundImage: imageURL,
          });
        },
        fail: (error) => {
          console.error('Error fetching image URL:', error);
        }
      });
 
    },
    onShow: function() {
       const userInfo = wx.getStorageSync('userInfo');
     
      if (userInfo) {
        this.setData({
          hasUserInfo: true,
          userInfo: userInfo
        });
      } 
    },
  }
})
